// pages/newsinformation/newsinformation.js
const app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indexdd: 0,
    indexddd:0,
    imgtypes: ["近期活动", "比赛展览", "干货分享", "征稿"],
    works:[
      { src:app.data.imgurl +"swiper.png", title: "2019“伯奇杯”中国创意摄影展活动", content:"为纪念中国近代科学先驱邹伯奇的重要贡献，弘扬培育邹伯奇“敢为人",browse:"50"},  // 浏览次数
      { src:app.data.imgurl +"swiper.png", title: "2019“伯奇杯”中国创意摄影展活动", content: "为纪念中国近代科学先驱邹伯奇的重要贡献，弘扬培育邹伯奇“敢为人", browse: "50" },
      { src:app.data.imgurl +"swiper.png", title: "2019“伯奇杯”中国创意摄影展活动", content: "为纪念中国近代科学先驱邹伯奇的重要贡献，弘扬培育邹伯奇“敢为人", browse: "50" },
      { src:app.data.imgurl +"swiper.png", title: "2019“伯奇杯”中国创意摄影展活动", content: "为纪念中国近代科学先驱邹伯奇的重要贡献，弘扬培育邹伯奇“敢为人", browse: "50" },
    ],
    rightarrow:app.data.imgurl +"rightarrow.png",  //右箭头
    fire:app.data.imgurl +"fire.png", // 火
    lefttop:app.data.imgurl +"lefttop.png", //左上角
    trophy:app.data.imgurl +"trophy.png",//奖杯
    frequnecy:app.data.imgurl +"worksnumbert.png",// 作品数量
    driedfood: ["摄影器材", "后期教程", "技术分享"],
    matchs: [
      { src:app.data.imgurl +"swiper.png", title: "2019自然风景展", reward: "2000元现金+证书", date: "8月14日 - 8月30日", frequnecy: "21314" },
      { src:app.data.imgurl +"swiper.png", title: "2018自然风景展", reward: "5000元现金+证书", date: "8月14日 - 8月30日", frequnecy: "21314" }
    ],
    getganhuoclass: app.data.url +'sheyingjia/xindex1/getganhuoclass',
    gethuodonglist: app.data.url + 'sheyingjia/Xpage1/gethuodonglist',
    getbisailist: app.data.url + 'sheyingjia/Xpage1/getbisailist',
    getzhengaolist: app.data.url + 'sheyingjia/Xpage1/getzhengaolist',
    getfenxianglist: app.data.url + 'sheyingjia/Xpage1/getfenxianglist',
    huodongpage:1,
    bisaipage:1,
    zhengaopage:1,
    huodong:[],
    bisai:[],
    zhenggao:[]

  },
  //点击导航栏
  ssx: function (e) {
    console.log(e)
    var indexdd = e.currentTarget.dataset.index;
    this.setData({
      indexdd: indexdd
    })
  },
   //点击干货分享的 下面的导航标题
  qiehuan:function(e){
    var indexddd = e.currentTarget.dataset.index;
    console.log(indexddd);
  this.setData({
    indexddd: e.currentTarget.dataset.index
  })
  },
  // 活动详情
  toxqactivity:function(e){
    // console.log(e);
    var id= e.currentTarget.dataset.id;
   wx.navigateTo({
     url: '/pages/xqactivity/xqactivity?id='+id,
   })

  },
  //跳转到征稿
  toxqactivitys:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/xqactivitys/xqactivitys?id=' + id,
    })
  },
   //查看比赛详情
  toxamatch:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/xqmatch/xqmatch?id='+id,
    })
  },
  
  //干货分享
  todriedfood: function (e) {
    var id  = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/xqdriedfood/xqdriedfood?id='+id,
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    ea.request(this.data.getganhuoclass,{},function(res){
      var data = res.data;
      console.log(data);
      if(data.code==200){
        var shuju =[];
        
        ea.each(data.data,function(i,v){
          v.page = 1;
          v.child = [];
          shuju.push(v);
        })
        that.setData({ driedfood: shuju});
        ea.each(data.data,function(i,v){
          that.getfenxiang(i);
        })
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    });
    this.gethuodong();
    this.getbisai();
    this.getzhenggao();
  },
  //获取活动数据
  gethuodong:function(){
    var page = this.data.huodongpage;
    console.log(page);
    var that = this;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      })
      return;
    }
    wx.showLoading({
      title: '加载中',
    })
    ea.request(this.data.gethuodonglist,{page:page},function(res){
      wx.hideLoading();
      var data = res.data;
      // console.log(data);
      if(data.code==200){
        if(data.data.length<10){
          that.setData({huodongpage:0})
        }else{
          that.setData({ huodongpage:page+1})
        }
        var huodong = that.data.huodong;
        huodong = ea.addArray(huodong,data.data);
        // console.log(huodong);
        that.setData({huodong:huodong});
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    })
  },
  //获取比赛数据
  getbisai:function(){
    var that = this;
    var page = that.data.bisaipage;
    if (page == 0) {
      wx.showToast({
        title: '没有更多了',
        icon: 'none'
      })
      return;
    }
    wx.showLoading({
      title: '加载中',
    })
    ea.request(this.data.getbisailist,{page:page},function(res){
      wx.hideLoading();
      var data = res.data;
      // console.log(data);
      if(data.code==200){
        if(data.data.length<10){
          that.setData({bisaipage:0});
        }else{
          that.setData({bisaipage:page+1});
        }
        var bisai = that.data.bisai;
        bisai = ea.addArray(bisai,data.data);
        // console.log(bisai);
        that.setData({bisai:bisai});
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    })
  },
  //获取征稿数据
  getzhenggao:function(){
    var page = this.data.zhengaopage;
    var that = this;
    if (page == 0) {
      wx.showToast({
        title: '没有更多了',
        icon: 'none'
      })
      return;
    }
    wx.showLoading({
      title: '加载中',
    })
    // console.log('haha')
    ea.request(this.data.getzhengaolist,{page:page},function(res){
      wx.hideLoading();
      var data = res.data;
      // console.log(data);
      if(data.code==200){
        var zhenggao = that.data.zhenggao;
        if(data.data.length<10){
          that.setData({zhengaopage:0});
        }else{
          that.setData({zhengaopage:page+1});
        }
        zhenggao = ea.addArray(zhenggao,data.data);
        console.log(zhenggao);
        that.setData({zhenggao:zhenggao});
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    })
  },
  //获取分享数据
  getfenxiang:function(indexddd){
    var driedfood = this.data.driedfood;
    if(!indexddd){
      indexddd = this.data.indexddd;
    }
    var page = driedfood[indexddd].page;
    var cid = driedfood[indexddd].id;
    var child = driedfood[indexddd].child;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      })
      return;
    }
    var that = this;
    console.log(indexddd);
    ea.request(that.data.getfenxianglist,{page:page,cid:cid},function(res){
      var data = res.data;
      if(data.code==200){
        if (data.data.length < 10) {
          driedfood[indexddd].page = 0;
        } else {
          driedfood[indexddd].page = page + 1;
        }
        child = ea.addArray(child, data.data);
        // console.log(child);
        driedfood[indexddd].child = child;
        that.setData({ driedfood: driedfood });
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var indexdd = this.data.indexdd;
    // console.log(indexdd);
    if(indexdd==0){
      this.gethuodong();
    }else if(indexdd==1){
      this.getbisai();
    } else if (indexdd==3){
      this.getzhenggao();
    }else if(indexdd==2){
      this.getfenxiang();
    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})